package com.skyline.common.tag;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.TagSupport;

import com.skyline.common.util.WebHelper;

public class SetSessionAttrToVarTag extends TagSupport {
	private static final long serialVersionUID = -8769966897762067473L;
	private String key;
	private String var;

	public SetSessionAttrToVarTag() {
		super();
	}

	public void setKey(String key) {
		this.key = key;
	}
	
	public void setVar(String var) {
		this.var = var;
	}

	@Override
	public int doEndTag() throws JspException {
		HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
		Object value = WebHelper.getSessionAttribute(request, key);
		pageContext.setAttribute(var, value, PageContext.PAGE_SCOPE);
		return EVAL_BODY_INCLUDE;
	}

}
